<template>
    <div
        v-if="data.data.catArr && data.data.catArr.length > 1"
        class="cls-flex pdc-cat-con"
        :style="{ margin: `0 -${data.rpxStyle['margin-left']}px 1rem`, color: data.style.tabInitColor }"
    >
        <div
            class="pdc-cat-item cls-center cls-column"
            :style="{ color: index == 0 ? data.style.tabActiveColor : data.style.tabInitColor }"
            v-for="(cat, index) in data.data.catArr"
            :key="cat.cate_id"
        >
            <div style="flex: 1" class="cls-center">{{ cat.label }}</div>
            <div class="cat-line-sel" v-if="index == 0" :style="{ background: data.style.tabLineColor }"></div>
        </div>
    </div>
    <!-- 一行两个 -->
    <div v-if="data.style.styleType == 1" class="pdc-list">
        <div class="pdc-con" v-for="(good, gi) in data.data.data" :key="gi">
            <div class="pdc-two__img">
                <img :src="good.img" />
                <!-- 遮罩层 -->
                <view class="left-two-overlay" v-if="good.sku == 0">已售罄</view>
            </div>
            <div style="padding: 10px 8px">
                <div class="pdc-one__line">
                    <div class="line-one pdc-title" :style="{ fontWeight: data.style.weight }">
                        {{ good.product_name }}
                    </div>
                    <div class="pdc-one__level" :style="{ color: data.style.price_color,fontWeight: data.style.weight }" v-if="good.level">{{ good.level }}级</div>
                </div>
                <div class="pdc-tip">{{ good.color }}; {{ good.norm }}/{{ good.unit }}</div>
                <div class="pdc-tag-list cls-flex" v-if="data.style.showSupp">
                    <div class="padc-tag__supp line-one" v-if="good.supplier">{{ good.supplier.title }}</div>
                    <template v-for="(tag, tag_index) in good.supplier.tag_list" :key="tag.tag_id">
                        <div class="pdc-tag" v-if="tag_index < 2">
                            {{ tag.title }}
                        </div>
                    </template>
                </div>
                <div class="cls-between" style="align-items: flex-end">
                    <div>
                        <span style="font-size: 12px" :style="{ fontWeight: data.style.weight, color: data.style.price_color }">￥</span>
                        <span style="font-size: 16px" :style="{ fontWeight: data.style.weight, color: data.style.price_color }">{{ good.product_price }}</span>
                        <span class="c-grey" style="font-size: 12px">/{{ good.unit }} 剩余:{{ good.sku }}{{ good.unit }}</span>
                    </div>
                    <img class="foot-buy" :src="proxy.imgUrl + 'tenant_593be52a46f869eea8b31d146d21de7a/album/202304/20230427_949efb995bbfcb188ad356f95ed446b7.png'" v-if="data.style.showBuy" />
                </div>
            </div>
        </div>
        <div v-if="!data.data.data || !data.data.data.length" class="cls-center cls-column" style="width: 100%; padding-top: 1rem">
             <img :src="proxy.imgUrl + 'tenant_593be52a46f869eea8b31d146d21de7a/album/202304/20230413_a14d3c70d6355877771685f19a24abb6.png'" style="width: 200px; height: auto" />
            <div class="none-text">暂无商品</div>
        </div>
    </div>
    <!-- 一行一个 -->
    <div class="pdc-one" v-else>
        <div class="cls-flex" v-for="(good, gi) in data.data.data" :key="gi" style="padding-bottom: 12px">
            <div class="pdc-one__img">
                <img :src="good.img" />
                <!-- 遮罩层 -->
                <view class="left-two-overlay" v-if="good.sku == 0">已售罄</view>
            </div>
            <div class="cls-column pdc-one__right">
                <div>
                    <div class="pdc-one__line">
                        <div class="line-one pdc-title" :style="{ fontWeight: data.style.weight }">
                            {{ good.product_name }}
                        </div>
                        <div class="pdc-one__level" :style="{ color: data.style.price_color,fontWeight: data.style.weight }" v-if="good.level">{{ good.level }}级</div>
                    </div>

                    <div class="pdc-tip">{{ good.color }}; {{ good.norm }}/{{ good.unit }}; 剩余:{{ good.sku }}{{ good.unit }}</div>
                    <div class="pdc-tag-list cls-flex" v-if="data.style.showSupp">
                        <div class="padc-tag__supp line-one" v-if="good.supplier">{{ good.supplier.title }}</div>
                        <template v-for="(tag, tag_index) in good.supplier.tag_list" :key="tag.tag_id">
                            <div class="pdc-tag" v-if="tag_index < 2">
                                {{ tag.title }}
                            </div>
                        </template>
                    </div>
                </div>
                <div class="cls-between">
                    <div>
                        <span style="font-size: 12px" :style="{ fontWeight: data.style.weight, color: data.style.price_color }">￥</span>
                        <span style="font-size: 16px" :style="{ fontWeight: data.style.weight, color: data.style.price_color }">{{ good.product_price }}</span>
                        <span class="c-grey" style="font-size: 12px">/{{ good.unit }}</span>
                    </div>
                    <img class="foot-buy" :src="proxy.imgUrl + 'tenant_593be52a46f869eea8b31d146d21de7a/album/202304/20230427_949efb995bbfcb188ad356f95ed446b7.png'" v-if="data.style.showBuy" />
                </div>
            </div>
        </div>
        <div v-if="!data.data.data.length" class="cls-center cls-column" style="width: 100%; padding-top: 1rem">
            <img :src="proxy.imgUrl + 'tenant_593be52a46f869eea8b31d146d21de7a/album/202304/20230413_a14d3c70d6355877771685f19a24abb6.png'" style="width: 200px; height: auto" />
            <div class="none-text">暂无商品</div>
        </div>
    </div>
</template>

<script setup>
import { getCurrentInstance } from "vue"

const { proxy } = getCurrentInstance()

/**
 * 商品列表
 * @property {Object} pageData  页面数据
 */
const props = defineProps({
    data: {
        type: Object,
        default: {
            id: 3,
            data: {
                catArr: [],
                /**请求地址*/
                reqUrl: "",
                /**请求参数*/
                reqData: {},
                /* 当没有请求地址的时候，使用data数据 */
                data: [],
            },
        },
    },
})
</script>

<style lang="less" scoped>
.left-two-overlay {
    z-index: 2;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 15px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 5px;
    overflow: hidden;
}
.none-text {
    margin-top: -10px;
    margin-bottom: 30px;
    color: #969799;
}
.pdc-list {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    width: 100%;
    .pdc-two__img {
        width: 100%;
        height: 140px;
        overflow: hidden;
        position: relative;
        flex: none;
        img {
            width: 100%;
            height: 100%;
        }
    }
    .pdc-con {
        width: 48.5%;
        background: #fff;
        border-radius: 5px;
        overflow: hidden;
        margin-bottom: 12px;
    }
}

.pdc-one__line {
    width: 100%;
    display: flex;
    align-items: center;
    .pdc-title {
        font-size: 14px;
        color: #323233;
    }
    .pdc-one__level {
        margin-left: 5px;
        font-size: 14px;
        flex: none;
    }
}

.pdc-tip {
    font-size: 10px;
    color: #606881;
    padding: 4px 0 3px;
}

.pdc-tag-list {
    margin-bottom: 4px;
    .pdc-tag {
        border-radius: 2px;
        background: #ffeeea;
        padding: 1px 3px;
        font-size: 10px !important;
        color: #fd7047;
        margin-right: 4px;
    }
    .padc-tag__supp {
        font-size: 13px;
        color: #606881;
        margin-right: 3px;
        max-width: 65px;
    }
}

.pdc-one {
    background: #fff;
    padding: 12px 14px 0;
    .pdc-one__right {
        margin-left: 10px;
        min-height: 90px;
        justify-content: space-between;
        flex: 1;
        overflow: hidden;
    }
    .pdc-one__img {
        width: 90px;
        height: 90px;
        border-radius: 5px;
        overflow: hidden;
        position: relative;
        flex: none;
        img {
            width: 100%;
            height: 100%;
        }
    }
}

.pdc-cat-con {
    background-color: #fff;
    // box-shadow: 0 2px 12px rgb(100 101 102 / 20%);
    height: 44px;
    font-size: 14px;
    overflow: hidden;
}

.pdc-cat-item {
    padding: 0 1rem;
    flex: 1;
    text-align: center;
    white-space: nowrap;
    height: 44px;
}
.cat-item-sel {
    font-weight: bold;
}
.cat-line-sel {
    width: 3rem;
    height: 3px;
    border-radius: 3px;
}

.c-grey {
    color: #606881;
}

.foot-buy {
    width: 24px;
    height: 24px;
}
</style>
